package Admin;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Window;
import java.util.ArrayList;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.JTextArea;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ViewAnswer extends JFrame {

	private JPanel contentPane;
	private JLabel lblNewLabel;
	private JLabel lblId;
	private JLabel label_1;
	private JLabel label_2;
	private JLabel label_3;
	private JLabel label_4;
	private JLabel label_5;
	private JScrollPane scrollPane;
	private JButton btnNewButton;
	private JScrollPane scrollPane_1;
	private JTable table;
	private JTextArea textArea;
	private JLabel prno;
	private JLabel mid;
	private JLabel subject;
	private JLabel wdate;
	private JLabel category;
	private JLabel tel;
	ArrayList<QnAVo> al;
	ManageDTO dto;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ViewAnswer frame = new ViewAnswer();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	
	public ViewAnswer(int rno,String pmid) {
		this();
		prno.setText(""+rno);
		mid.setText(pmid);
		
		al = new ArrayList<QnAVo>();
		dto = new ManageDTO();
		al = dto.selectAnswer(rno);
		Vector<String> vec = new Vector<String>();
		
		vec.add("No");
		vec.add("카테고리");
		vec.add("제목");
		vec.add("작성일");
		
		DefaultTableModel tmodel = new DefaultTableModel(vec, 0);
		
		if(al.size()>0){
		
			
			
			for (QnAVo vo : al) {
				Vector v = new Vector();
				
				v.add(vo.getRno());
				v.add(vo.getCategory());
				v.add(vo.getSubject());
				v.add(vo.getWdate());
				
				tmodel.addRow(v);
				
			}
		}
		table.setModel(tmodel);
		
		
	}
	
	public ViewAnswer() {
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 421, 571);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		contentPane.add(getLblNewLabel());
		contentPane.add(getLblId());
		contentPane.add(getLabel_1());
		contentPane.add(getLabel_2());
		contentPane.add(getLabel_3());
		contentPane.add(getLabel_4());
		contentPane.add(getLabel_5());
		contentPane.add(getScrollPane());
		contentPane.add(getBtnNewButton());
		contentPane.add(getScrollPane_1());
		contentPane.add(getPrno());
		contentPane.add(getMid());
		contentPane.add(getSubject());
		contentPane.add(getWdate());
		contentPane.add(getCategory());
		contentPane.add(getTel());
	}

	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("질문 번호 : ");
			lblNewLabel.setFont(new Font("Gulim", Font.PLAIN, 12));
			lblNewLabel.setBounds(12, 26, 70, 15);
		}
		return lblNewLabel;
	}
	private JLabel getLblId() {
		if (lblId == null) {
			lblId = new JLabel("고객 ID : ");
			lblId.setFont(new Font("Gulim", Font.PLAIN, 12));
			lblId.setBounds(145, 26, 57, 15);
		}
		return lblId;
	}
	private JLabel getLabel_1() {
		if (label_1 == null) {
			label_1 = new JLabel("제 목 : ");
			label_1.setFont(new Font("Gulim", Font.PLAIN, 12));
			label_1.setBounds(12, 126, 57, 15);
		}
		return label_1;
	}
	private JLabel getLabel_2() {
		if (label_2 == null) {
			label_2 = new JLabel("작성일 : ");
			label_2.setFont(new Font("Gulim", Font.PLAIN, 12));
			label_2.setBounds(12, 151, 57, 15);
		}
		return label_2;
	}
	private JLabel getLabel_3() {
		if (label_3 == null) {
			label_3 = new JLabel("카테고리 : ");
			label_3.setFont(new Font("Gulim", Font.PLAIN, 12));
			label_3.setBounds(12, 176, 70, 15);
		}
		return label_3;
	}
	private JLabel getLabel_4() {
		if (label_4 == null) {
			label_4 = new JLabel("연락처 : ");
			label_4.setFont(new Font("Gulim", Font.PLAIN, 12));
			label_4.setBounds(12, 201, 57, 15);
		}
		return label_4;
	}
	private JLabel getLabel_5() {
		if (label_5 == null) {
			label_5 = new JLabel("내 용");
			label_5.setFont(new Font("Gulim", Font.PLAIN, 12));
			label_5.setBounds(12, 226, 57, 15);
		}
		return label_5;
	}
	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setBounds(12, 251, 381, 217);
			scrollPane.setViewportView(getTextArea());
		}
		return scrollPane;
	}
	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("닫기");
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					
					dispose();
					
				}
			});
			btnNewButton.setBounds(296, 478, 97, 23);
		}
		return btnNewButton;
	}
	private JScrollPane getScrollPane_1() {
		if (scrollPane_1 == null) {
			scrollPane_1 = new JScrollPane();
			scrollPane_1.setBounds(12, 55, 381, 61);
			scrollPane_1.setViewportView(getTable());
		}
		return scrollPane_1;
	}
	private JTable getTable() {
		if (table == null) {
			table = new JTable();
			table.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseReleased(MouseEvent e) {
					QnAVo v = new QnAVo();
					dto = new ManageDTO();
					v = dto.selectoneQnA((Integer)table.getValueAt(table.getSelectedRow(), 0));
					
					subject.setText(v.getSubject());
					wdate.setText(v.getWdate().toString());
					category.setText(v.getCategory());
					tel.setText(v.getTel());
					textArea.setText(v.getContent());
					
				}
			});
		}
		return table;
	}
	private JTextArea getTextArea() {
		if (textArea == null) {
			textArea = new JTextArea();
		}
		return textArea;
	}
	private JLabel getPrno() {
		if (prno == null) {
			prno = new JLabel("");
			prno.setFont(new Font("Gulim", Font.PLAIN, 12));
			prno.setBounds(82, 26, 57, 15);
		}
		return prno;
	}
	private JLabel getMid() {
		if (mid == null) {
			mid = new JLabel("");
			mid.setFont(new Font("Gulim", Font.PLAIN, 12));
			mid.setBounds(201, 26, 105, 15);
		}
		return mid;
	}
	private JLabel getSubject() {
		if (subject == null) {
			subject = new JLabel("");
			subject.setFont(new Font("Gulim", Font.PLAIN, 12));
			subject.setBounds(62, 126, 244, 15);
		}
		return subject;
	}
	private JLabel getWdate() {
		if (wdate == null) {
			wdate = new JLabel("");
			wdate.setFont(new Font("Gulim", Font.PLAIN, 12));
			wdate.setBounds(62, 151, 244, 15);
		}
		return wdate;
	}
	private JLabel getCategory() {
		if (category == null) {
			category = new JLabel("");
			category.setFont(new Font("Gulim", Font.PLAIN, 12));
			category.setBounds(82, 176, 224, 15);
		}
		return category;
	}
	private JLabel getTel() {
		if (tel == null) {
			tel = new JLabel("");
			tel.setFont(new Font("Gulim", Font.PLAIN, 12));
			tel.setBounds(62, 201, 244, 15);
		}
		return tel;
	}
}
